﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class ePioneer_Center_ep_versions : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string strPage = Request["page"];
            int page = 1;
            try
            {
                page = int.Parse(strPage);
                if (page < 1)
                {
                    page = 1;
                }
            }
            catch (Exception ex)
            {
                page = 1;
            }
            bd(page);
        }
    }

    protected void btn_Add_Click(object sender, EventArgs e)
    {
        CMS.BLL.EPioneerVersionsBLL bll = new CMS.BLL.EPioneerVersionsBLL();
        CMS.Entity.EPioneerVersionsModel model = new CMS.Entity.EPioneerVersionsModel();
        model.isPub = "0";
        model.create_time = DateTime.Now;
        model.clientver = txt_Versions.Text.Trim();
        model.description = txt_Description.Text.Trim();
        model.outver = txt_VersionsOut.Text.Trim();
        if (bll.Add(model))
        {
            bd(AspNetPager1.CurrentPageIndex);
        }
        else
        {
            ClientScript.RegisterStartupScript(GetType(), "pub", "alert('添加失败，请重试！');", true);
            return;
        }
    }

    protected void btnPub_Click(object sender, EventArgs e)
    {
        CMS.BLL.EPioneerVersionsBLL bll = new CMS.BLL.EPioneerVersionsBLL();
        string[] list = hidIds.Value.Split(',');
        if (list.Length > 0 && list[0] != "")
        {
            if (bll.Update(list, "1"))
            {
                bd(AspNetPager1.CurrentPageIndex);
            }
            else
            {
                ClientScript.RegisterStartupScript(GetType(), "pub", "alert('启用失败，请重试！');", true);
                return;
            }
        }
        else
        {
            ClientScript.RegisterStartupScript(GetType(), "pub", "alert('没有选中启用项');", true);
            return;
        }
    }

    protected void btnCancelPub_Click(object sender, EventArgs e)
    {
        CMS.BLL.EPioneerVersionsBLL bll = new CMS.BLL.EPioneerVersionsBLL();
        string[] list = hidIds.Value.Split(',');
        if (list.Length > 0 && list[0] != "")
        {
            if (bll.Update(list, "0"))
            {
                bd(AspNetPager1.CurrentPageIndex);
            }
            else
            {
                ClientScript.RegisterStartupScript(GetType(), "pub", "alert('取消失败，请重试！');", true);
                return;
            }
        }
        else
        {
            ClientScript.RegisterStartupScript(GetType(), "pub", "alert('没有选中取消项');", true);
        }
    }

    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        bd(AspNetPager1.CurrentPageIndex);
    }

    private void bd(int page)
    {
        CMS.BLL.EPioneerVersionsBLL bll = new CMS.BLL.EPioneerVersionsBLL();

        List<CMS.Entity.EPioneerVersionsModel> data = bll.GetListEPioneerVersions();
        if (data != null && data.Count > 0)
        {
            AspNetPager1.RecordCount = data.Count;
            AspNetPager1.CurrentPageIndex = page;
            IEnumerable<CMS.Entity.EPioneerVersionsModel> res = data.Skip((page - 1) * AspNetPager1.PageSize).Take(AspNetPager1.PageSize);
            RepeaterVersions.DataSource = res;
            RepeaterVersions.DataBind();
        }
    }
}